using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerHardLandingState : PlayerLandingState
{
    public PlayerHardLandingState(PlayerMovementMachine stateMachine) : base(stateMachine)
    {
    }
    
#region IState Methods
    public override void Enter()
    {
        base.Enter();
        StateMachine.ReusableData.MovementSpeedModify = 0;
        ResetVelocity();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.Disable();
        StartAnimation(StateMachine.Player.AnimationData.HardLandParameterHash);        
    }

    public override void Exit()
    {
        base.Exit();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.Enable();
        StopAnimation(StateMachine.Player.AnimationData.HardLandParameterHash);        
    }

    public override void OnAnimationExitEvent()
    {
        base.OnAnimationExitEvent();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.Enable();
    }

    public override void OnAnimationTransitionEvent()
    {
        StateMachine.ChangeState(StateMachine.IdlingState);
    }
    
    public override void PhysicUpdate()
    {
        base.PhysicUpdate();
        if (!IsMovingHorizontally())
        {
            return;
        }
        
        ResetVelocity();
    }
#endregion

#region Reusable Methods
    protected override void AddInputActionsCallBacks()
    {
        base.AddInputActionsCallBacks();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.started += OnMovementStarted;
    }

    protected override void RemoveInputActionsCallBacks()
    {
        base.RemoveInputActionsCallBacks();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.started -= OnMovementStarted;
    }

    protected override void OnMove()
    {
        if (StateMachine.ReusableData.ShouldWalk)
            return;
        
        StateMachine.ChangeState(StateMachine.RunningState);
    }
#endregion

#region Input Methods
    private void OnMovementStarted(InputAction.CallbackContext context)
    {
        OnMove();
    }

    protected override void OnJumpPerformed(InputAction.CallbackContext context)
    {
    }
#endregion
}
